
import { getToken, setToken } from '@/utils/auth'

const user = {
  state: {
    token: getToken(),
    name: '',
    roles: [],
    userId: ''
  },
  mutations: {
    SET_TOKEN: (state, token) => {
      state.token = token
    },
    SET_NAME: (state, name) => {
      state.name = name
    },
    SET_ROLES: (state, roles) => {
      state.roles = roles
    },
    SET_ID: (state, id) => {
      state.userId = id
    }
  },
  actions: {
    // 登录
    Login({ commit }, userInfo) {
      const username = userInfo.username.trim()
      return new Promise((resolve, reject) => {
        // login(username, userInfo.password, userInfo.identificationCode).then(response => {
        //   const data = response.data
        //   if (+response.code === 0) {
        //     setToken(data.access_token)
        //     commit('SET_TOKEN', data.access_token)
        //     setRefreshToken(data.refresh_token)
        //     resolve('登录成功')
        //   } else {
        //     reject(response)
        //   }
        // }).catch(error => {
        //   reject(error)
        // })
      })
    },
    // 获取用户信息
    GetInfo({ commit, state }) {
      return new Promise((resolve, reject) => {
        
      })
    },

    // 登出
    LogOut({ commit, state }) {
      return new Promise((resolve, reject) => {
        
      })
    },

    // 前端 登出
    FedLogOut({ commit }) {
      return new Promise(resolve => {
       
        clearAllCache()
        resolve()
      })
    }
  }
}

export default user